package com.shuyuansystem.service.impl;


import com.shuyuansystem.dao.ReviewsMapper;
import com.shuyuansystem.entity.Result;
import com.shuyuansystem.pojo.Reviews;
import com.shuyuansystem.service.ReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReviewsServiceImpl implements ReviewsService {

    @Autowired
    private ReviewsMapper reviewsMapper;

    // 之前的方法保持不变
    @Override
    public Reviews insertReviews(Reviews reviews) {
        int rows = reviewsMapper.insertReviews(reviews);
        if (rows > 0) {
            return reviews;
        }
        return null;
    }

    @Override
    public List<Reviews> getReviewsByProductId(Integer productId) {
        return reviewsMapper.getReviewsByProductId(productId);
    }

    // 新增删除评论实现
    @Override
    public Result deleteReviewById(Integer reviewId) {
        int rows = reviewsMapper.deleteReviewById(reviewId);
        if (rows > 0) {
            return new Result(true, "删除成功");
        }
        return new Result(false, "删除失败，评论可能不存在");
    }

    // 新增修改评论实现
    @Override
    public Result updateReview(Integer reviewId, String reviewContent) {
        int rows = reviewsMapper.updateReview(reviewId, reviewContent);
        if (rows > 0) {
            return new Result(true, "修改成功");
        }
        return new Result(false, "修改失败，评论可能不存在");
    }
}